<%@page import="org.yate.oa.model.LoginEntity"%>
<%@page import="java.text.SimpleDateFormat, java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="${pageContext.request.contextPath}" var="ctx" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>绩效列表（助理）</title>
<link href="${ctx}/css/skin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/backOffice.js"></script>
<script type="text/javascript">
	
<%LoginEntity user = (LoginEntity) session.getAttribute("user");%>
	var currentUserId =
<%=user.getUserId()%>
	;

	function zlSH(op, pid) {
		var obj = {};
		obj.type = "changestatus";
		if (op == "1") {
			//助理审核通过
			obj.status = "zlcompleted";
		} else if (op == "2") {
			//助理审核不通过
			obj.status = "complete";
		}
		obj.pid = pid;
		$.ajax({
			type : 'post',
			dataType : 'json',
			data : obj,
			url : '${ctx}/performance/post',
			success : function(data) {
				if (data.code == 200) {
					$.msgbox.show({
						message : "操作成功",
						icon : 'ok',
						beforeHide : function() {
							location.reload();
						}
					});
				} else {
					$.msgbox.show({
						message : data.msg,
						icon : 'no',
						beforeHide : function() {
							location.reload();
						}
					});
				}
			}
		});
	}
	function loadPs() {
		var obj = {};
		obj.type = "zlgetmyps";
		var date = new Date();
		if (parseInt($("#selMonth").val()) < 10) {
			obj.date = date.getFullYear() + "0"
					+ parseInt($("#selMonth").val());
		} else {
			obj.date = date.getFullYear() + "" + parseInt($("#selMonth").val());
		}
		$
				.ajax({
					type : 'post',
					dataType : 'json',
					data : obj,
					url : '${ctx}/performance/post',
					success : function(data) {
						var rows = data.data;
						var str = '';
						var c0 = 0, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0;
						var tmpTotalScore = 0;
						for ( var i = 0; i < rows.length; i++) {
							if (rows[i].status == "initialize") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a href="zl-performance.jsp?target='
										+ rows[i].targetUserId
										+ '&createrId='
										+ rows[i].createrId
										+ '">编辑</a> <a href="javascript:void(0);" onclick="distributedP('
										+ rows[i].id + ')">派发</a></div>';
							} else if (rows[i].status == "distributed") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a target="_blank" href="performance-show.jsp?from=zl&pid='
										+ rows[i].id
										+ '">浏览</a><span>已派发</span></div>';
							} else if (rows[i].status == "processiong") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a target="_blank" href="performance-show.jsp?from=zl&pid='
										+ rows[i].id
										+ '">浏览</a><span>待考评</span></div>';
							} else if (rows[i].status == "complete") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a target="_blank" href="performance-show.jsp?from=zl&pid='
										+ rows[i].id
										+ '">浏览</a><span>等待主管打分</span></div>';
							} else if (rows[i].status == "completed") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a target="_blank" href="performance-show.jsp?from=zl&pid='
										+ rows[i].id
										+ '">浏览</a><a title="通过后则进入HR终审" href="javascript:void(0);" onclick="zlSH(1,'
										+ rows[i].id
										+ ')">通过</a><a title="不通过则重新打回给被考核者自评" href="javascript:void(0);" onclick="zlSH(2,'
										+ rows[i].id
										+ ')">不通过</a><span style="color:green;font-weight:bold;">已完成('
										+ rows[i].totalScore + ')</span></div>';
							} else if (rows[i].status == "zlcompleted") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a target="_blank" href="performance-show.jsp?from=zl&pid='
										+ rows[i].id
										+ '">浏览</a><span>等待HR终审</span></div>';
							} else if (rows[i].status == "hrcompleted") {
								str += '<div class="divPerformanceGird"><h1>'
										+ rows[i].partName
										+ '</h1><a target="_blank" href="performance-show.jsp?from=zl&pid='
										+ rows[i].id
										+ '">浏览</a><span style="color:red;font-weight:bold;">HR审核通过</span></div>';
							}

							if (rows[i].status == "completed"
									|| rows[i].status == "zlcompleted") {
								c0++;
								tmpTotalScore = parseFloat(rows[i].totalScore);
								if (tmpTotalScore == 0) {
									c1++;
								} else if (tmpTotalScore < 80) {
									c2++;
								} else if (tmpTotalScore >= 80
										&& tmpTotalScore < 90) {
									c3++;
								} else if (tmpTotalScore >= 90
										&& tmpTotalScore <= 95) {
									c4++;
								} else if (tmpTotalScore > 95
										&& tmpTotalScore <= 100) {
									c5++;
								} else if (tmpTotalScore > 100
										&& tmpTotalScore <= 105) {
									c6++;
								} else if (tmpTotalScore > 105) {
									c7++;
								}
							}
						}
						$("#tdParts")
								.html(
										'有效总数：'
												+ c0
												+ '个，&nbsp;&nbsp;&nbsp;80分(0)以下：'
												+ c2
												+ '个，&nbsp;&nbsp;&nbsp;80-90分(0.5)不含90分：'
												+ c3
												+ '个，&nbsp;&nbsp;&nbsp;90-95分(0.8)：'
												+ c4
												+ '个，&nbsp;&nbsp;&nbsp;95以上-100分(1.0)：'
												+ c5
												+ '个，&nbsp;&nbsp;&nbsp;100以上-105分(1.1)：'
												+ c6
												+ '个，&nbsp;&nbsp;&nbsp;105分(1.2)以上：'
												+ c7 + '个');
						$("#tdPerformances").html(str);
					}
				});
	}
	//派发
	function distributedP(pid) {
		if (confirm("派发后不可更改，您确定要派发吗？")) {
			var obj = {};
			obj.type = "distributed";
			obj.pid = pid;
			$.ajax({
				type : 'post',
				dataType : 'json',
				data : obj,
				url : '${ctx}/performance/post',
				success : function(data) {
					if (data.code == 200) {
						//alert("派发成功，已经通知目标用户进行自评。");
						$.msgbox.show({
							message : "派发成功，已经通知目标用户进行自评。",
							icon : 'ok',
							beforeHide : function() {
								location.reload();
							}
						});
					} else {
						//alert(data.msg);
						$.msgbox.show({
							message : data.msg,
							icon : 'no'
						});
					}
				}
			});
		}
	}

	$(document).ready(function() {
		for ( var i = 1; i <= 12; i++) {
			$("#selMonth").append("<option value='"+i+"'>" + i + "</option>");
		}
		$("#selMonth").val((new Date().getMonth()+1));
		$("#selMonth").change(function() {
			loadPs();
		});
		loadPs();
	});
</script>
</head>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" height="29" valign="top"
				background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/left-top-right.gif" width="17" height="29" /></td>
			<td width="" height="29" valign="top"
				background="${ctx}/images/content-bg.gif"><table width="100%"
					height="31" border="0" cellpadding="0" cellspacing="0"
					class="left_topbg" id="table2">
					<tr>
						<td height="31"><div class="titlebt">绩效列表</div></td>
					</tr>
				</table></td>
			<td width="16" valign="top"
				background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/nav-right-bg.gif" width="16" height="29" /></td>
		</tr>
		<tr>
			<td height="71" valign="middle"
				background="${ctx}/images/mail_leftbg.gif">&nbsp;</td>
			<td valign="top" bgcolor="#F7F8F9"><table width="100%"
					height="138" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="13" valign="top">&nbsp;</td>
					</tr>
					<tr>
						<td valign="top"><table width="98%" border="0" align="center"
								cellpadding="0" cellspacing="0">
								<tr>
									<td class="left_txt">当前位置：绩效列表 &nbsp;&nbsp;&nbsp;&nbsp;<select
										id="selMonth"></select>月
									</td>
								</tr>
								<tr>
									<td height="20"><table width="100%" height="1" border="0"
											cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
											<tr>
												<td></td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td id="tdParts"></td>
								</tr>
								<tr>
									<td id="tdPerformances"></td>
								</tr>
								<tr>
									<td width="100%" valign="top"
										style="min-height: 350px; height: 350px;"></td>
								</tr>
							</table></td>
					</tr>
				</table></td>
			<td background="${ctx}/images/mail_rightbg.gif">&nbsp;</td>
		</tr>
		<tr>
			<td valign="middle" background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/buttom_left2.gif" width="17" height="17" /></td>
			<td height="17" valign="top"
				background="${ctx}/images/buttom_bgs.gif"><img
				src="${ctx}/images/buttom_bgs.gif" width="17" height="17" /></td>
			<td background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/buttom_right2.gif" width="16" height="17" /></td>
		</tr>
	</table>
</body>
</html>